package players
{
	import flash.geom.Point;
	import net.flashpunk.Entity;
	import net.flashpunk.Graphic;
	import GC;
	import GV;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.utils.Input;
	import net.flashpunk.utils.Key;
	import net.flashpunk.graphics.Text;
	import net.flashpunk.FP;
	/**
	 * ...
	 * @author Alex
	 */
	public class Player extends Entity 
	{
		private var _player:Image;
		private var _v:Point;
		public function Player(p:Point) 
		{			
			x = p.x;
			y = p.y;
			_v = new Point;
			_player = new Image(GC.GFX_PLAYER);
			graphic = _player;
			layer = 1;
			//y = 380;
			setHitbox(64, 96);
			type = GC.PLAYER;
		}
		
		private function updateCollision():void 
		{
			//y += GV.PLAYER_SPEED;
			y += _v.y;
			
			if (collide(GC.LEVEL, x, y))
			{
				y = Math.floor(y / 32) * 32;
				//Reverse direction
				_v.x = -1 * _v.x;
			}
			
			x += _v.x;
			
			//if (collide(GC.RAMP, x, y))
			//{
				//var i:int = new int;
				//i = 0;
				//while (i < (Math.sqrt(34 * 34 * 2)))
				//{
					//y = y - 2;
					//x = x + 2;
					//i = i+2;
				//}
			//}
			
			if (collide(GC.ITEM, x, y))
			{
				var item:Entity = collide(GC.ITEM, x, y);
				FP.world.remove(item);
			}
			
			if (x > FP.screen.width) //loops the player back around
			{
				x = 0;
				
			}
			
		}
		
		private function updateMovement():void
		{
			var movement:Point = new Point;
			//if (Input.check(Key.UP)) movement.y = movement.y-50;
			//if (Input.check(Key.DOWN)) movement.y++;
			//if (Input.check(Key.LEFT)) movement.x--;
			//if (Input.check(Key.RIGHT)) movement.x++;
			//
			//_v.x = 200 * FP.elapsed * movement.x;
			//_v.y = 200 * FP.elapsed * movement.y;		
			
			if (Input.mousePressed)
			{
				for (var i:int = 0; i < 100; i++)
				{
					movement.x++;
					_v.x = 2 * FP.elapsed * movement.x;
					_v.y = 2 * FP.elapsed * movement.y;
				}
			}
		}
		
		override public function update():void 
		{
			updateMovement();
			updateCollision();
		}
	}

}